package com.moyq5.permit.center.bean.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.permit.center.bean.enums.SysPlatform;

/**
 * 权限
 * @author Moyq5
 * @date 2018年4月13日
 */
@Entity
@Table(name = "sys_permit")
@DynamicUpdate
public class SysPermit implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 权限ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "permit_id")
	private Long permitId;
	/**
	 * 上级权限
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id", insertable = false, updatable = false)
	private SysPermit parent;
	/**
	 * 上级权限ID
	 */
	@Column(name = "parent_id")
	private Long parentId;
	/**
	 * 级别
	 */
    @Column(name = "level", precision = 2)
	private Integer level;
    /**
	 * 权限名称
	 */
	@Column(name = "name", length = 60, nullable = false)
	private String name;
	/**
	 * 排序
	 */
	@Column(name = "sort", precision = 2, nullable = false)
	private Integer sort;
	/**
	 * 受限地址
	 */
	@Column(name = "path", length = 100)
	private String path;
	/**
	 * 权限值，受限地址基本权限标志
	 */
	@Column(name = "permit", length = 50)
	private String permit;
	/**
	 * 鉴权规则，通过此规则鉴权后方可访问受限地址，一般内容至少包含"权限值"内容
	 */
	@Column(name = "auth", length = 50)
	private String auth;
	/**
	 * 是否菜单
	 */
	@Column(name = "is_menu", nullable = false)
	private Boolean isMenu;
	/**
	 * 菜单或者权限按钮图标，可以是图片地址、css的class名称
	 */
	@Column(name = "icon", length = 100)
	private String icon;
	/**
	 * 标签，自定义分类标识
	 */
	@Column(name = "tag", length = 50)
	private String tag;
	/**
	 * 平台类型
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "platform", precision = 2, nullable = false)
	private SysPlatform platform;
    
    @PrePersist
    public void prePersist() {
    	if (null == isMenu) {
    		isMenu = false;
    	}
    }
	public Long getPermitId() {
		return permitId;
	}
	public void setPermitId(Long permitId) {
		this.permitId = permitId;
	}
	public SysPermit getParent() {
		return parent;
	}
	public void setParent(SysPermit parent) {
		this.parent = parent;
	}
	public Integer getLevel() {
		return level;
	}
	public void setLevel(Integer level) {
		this.level = level;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public SysPlatform getPlatform() {
		return platform;
	}
	public void setPlatform(SysPlatform platform) {
		this.platform = platform;
	}
	public String getPermit() {
		return permit;
	}
	public void setPermit(String permit) {
		this.permit = permit;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public Boolean getIsMenu() {
		return isMenu;
	}
	public void setIsMenu(Boolean isMenu) {
		this.isMenu = isMenu;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public Integer getSort() {
		return sort;
	}
	public void setSort(Integer sort) {
		this.sort = sort;
	}
	public Long getParentId() {
		return parentId;
	}
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	public String getAuth() {
		return auth;
	}
	public void setAuth(String auth) {
		this.auth = auth;
	}
	public String getTag() {
		return tag;
	}
	public void setTag(String tag) {
		this.tag = tag;
	}
	@Override
	public String toString() {
		return "SysPermit [permitId=" + permitId + ", parent=" + parent + ", parentId=" + parentId + ", level=" + level
				+ ", name=" + name + ", sort=" + sort + ", path=" + path + ", permit=" + permit + ", auth=" + auth
				+ ", tag=" + tag + ", isMenu=" + isMenu + ", icon=" + icon + ", platform=" + platform + "]";
	}
}
